package songgao.papers.iEC;

import java.util.ArrayList;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import javax.jdo.annotations.Extension;

@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable="true")
public class Individual {
	
	public static Individual generateIndividual()
	{
		Individual ind = new Individual();
		ind.gene = new ArrayList<Integer>();
		ind.fitness=Double.NaN;
		int lowerB = DataManager.INSTANCE.getParameters().getGeneLowerBound();
		int upperB = DataManager.INSTANCE.getParameters().getGeneUpperBound();
		for(int i = 0; i<DataManager.INSTANCE.getParameters().getGeneSize();i++)
		{
			ind.gene.add(DataManager.INSTANCE.getRandomizer().nextInt(upperB - lowerB + 1) + lowerB);
		}
		return ind;
	}
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    @Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true")
    private String encodedKey;
    
    @Persistent(defaultFetchGroup="true")
	private ArrayList<Integer> gene;
    
    @Persistent(defaultFetchGroup="true")
	private double fitness;
    
	/**
	 * @param encodedKey the encodedKey to set
	 */
	public void setEncodedKey(String encodedKey) {
		this.encodedKey = encodedKey;
	}

	/**
	 * @return the encodedKey
	 */
	public String getEncodedKey() {
		return encodedKey;
	}

	/**
	 * @param gene the gene to set
	 */
	public void setGene(java.util.ArrayList<Integer> gene) {
		this.gene = gene;
	}

	/**
	 * @return the gene
	 */
	public java.util.ArrayList<Integer> getGene() {
		return gene;
	}

	/**
	 * @param fitness the fitness to set
	 */
	public void setFitness(double fitness) {
		this.fitness = fitness;
	}

	/**
	 * @return the fitness
	 */
	public double getFitness() {
		return fitness;
	}
	
}
